#ifndef DATAMONITOR_H
#define DATAMONITOR_H
#include <QFileDialog>
#include <QWidget>
#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QDateTimeAxis>
#include <QtCharts/QValueAxis>
#include <QTimer>
#include <QTableWidget>
#include <QCheckBox>
#include <QJsonArray>
#include "../MainProject/sqlitedatabase.h"


namespace Ui {
class DataMonitor;
}

class DataMonitor : public QWidget
{
    Q_OBJECT

public:
    explicit DataMonitor(QWidget *parent = nullptr);
    ~DataMonitor();
    void setCurrentDevice(int deviceId); // 添加这个函数

signals:
    void temperatureDataUpdated(int value);
    void humidityDataUpdated(int value);
    void lightDataUpdated(int value);

private slots:
    void updateRealtimeData();
    void toggleTemperatureSeries(bool checked);
    void toggleHumiditySeries(bool checked);
    void toggleLightSeries(bool checked);
 //   void updateHistoricalData();
    void onViewHistoryButtonClicked();
    void onExportCsvButtonClicked();
private:
    Ui::DataMonitor *ui;
    QTimer *timer;
    QLineSeries *temperatureSeries;
    QLineSeries *humiditySeries;
    QLineSeries *lightSeries;
    QChart *chart;
    SQLiteDatabase *db;
    qint64 lastTimestamp;
    int currentDeviceId;
    QSet<qint64> processedTimestamps;//类似std::set0

    qint64 getOldestTimestamp();
    qint64 getNewestTimestamp();
    void clearData();
    qint64 oldestTimestamp;
    qint64 newestTimestamp;
};

#endif // DATAMONITOR_H
